<?php

/**
 * Homepage presenter.
 *
 * @author     John Doe
 * @package    MyApplication
 */
class HomepagePresenter extends BasePresenter
{
    public function renderDefault()
    {
	$this->template->allUsers = $this->model->getUsers();
	$this->template->anyVariable = 'any value';
	
	if($this->user->isLoggedIn())
	{
	    $this->template->userName = $this->model->getUserName($this->user->getIdentity()->getId());
	}
    }
    
    public function renderHelp()
    {

    } 
    
    public function renderProfile($id)
    {
	if(!$this->user->isLoggedIn()) {
	    $this->redirect('Sign:in');
	}
	
	// Ak sa id rovna id usera, zmen template !
	if($this->user->getId() == $id) {
	    $this->setView('profileOwn');
	}
	
	$row = $this->model->getUsers()->find($id)->fetch();
	// Existuje vobec taky user? Ak nie presmeruj na profil uzivatela
	if(!$row) {
	    $this->setView('profileOwn');
	}
	
	// Pozn.: Na miesto find($id)->fetch() sa da pouzit aj get($id)
	$this->template->profile = $row;
    }
    
    public function actionPage()
    {
	// pre renderovani novej stranky nezabudnut 
	// pouzit $this->setView('notFound') ak sa stranak nenajde
    }

}
